//
//  MyIterator.m
//  LearnObjectiveC
//
//  Created by client on 2017/9/9.
//  Copyright © 2017年 吴可高. All rights reserved.
//

#import "MyIterator.h"
@interface MyIterator()
{
    int pos;
}

@end
@implementation MyIterator
- (instancetype)init
{
    self = [super init];
    if (self) {
        pos = -1;
    }
    return self;
}

@synthesize collection;

-(void)setCollection:(Collection *)newCollection
{
    collection = newCollection;
}

-(NSObject *)previous
{
    if (pos > 0) {
        pos --;
    }
    return [collection getIndex:pos];
}

-(NSObject *)next
{
    int size = [collection size];
    if (pos <size -1) {
        pos ++;
    }
    return [collection getIndex:pos];
}

-(BOOL)hasNext
{
    [super hasNext];
    int size = [collection size];
    if (pos < size -1) {
        return YES;
    }
    else
    {
        return NO;
    }
}


-(NSObject *)first
{
    pos = 0;
    return [collection getIndex:pos];
}

@end
